import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { crx } from '@crxjs/vite-plugin'
import manifest from './manifest.json' assert { type: 'json' } // Node >=17
import path from 'path'
import babel from "vite-plugin-babel";

// https://vitejs.dev/config/
export default defineConfig({
  root: 'src/',
  plugins: [
    babel(),
    vue(),
    crx({ manifest }),
  ],
  build: {
    target: 'es2015',
    outDir: path.resolve(__dirname, 'dist'),
    // lib: {
    //   // Could also be a dictionary or array of multiple entry points
    //   entry: path.resolve(__dirname, 'src/contentPage/XHRreload.js'),
    //   name: 'MyLib',
    //   // the proper extensions will be added
    //   fileName: 'my-lib',
    // },
    rollupOptions: {
      input: {
        contentPage: path.resolve(__dirname, 'src/contentPage/index.html'),
        popup: path.resolve(__dirname, 'src/popup/index.html'),
        option: path.resolve(__dirname, 'src/options/index.html'),
      },
    
      output: {
        assetFileNames: 'assets/[name]-[hash].[ext]', // 静态资源
        chunkFileNames: 'js/[name]-[hash].js', // 代码分割中产生的 chunk
        entryFileNames: 'js/[name]-[hash].js'
      }
    }
  },
  
  server: {
    hmr: {
      clientPort: 5173,
    }   
  }
})
